import util from '../../utils/util'
import { EnumUserType } from '../../utils/constant.js'
const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '', // 企业Id
    enterprisedata:{},//企业信息数据
    account:'',//用户名
    password:'',//密码
    password2:'',//重复密码
    name:'',//企业全称
    nickname:'',//企业简称
    sociologyCreditCode:'',//统一社会信用代码
    addressDetail:'',//企业所在地址
    contacts:'',//招聘联系人
    mobileNum:'',//联系人手机号
    smsCode:'',//短信验证码
    identifyCode:'',//联系人身份证号
    email:'',//电子邮箱
    introduction:'',//企业简介
    editstate: false,//是否编辑
    qyindex:0, //企业性质索引
    qiyeArr:[],//企业性质
    qiye:'',///上传的企业性质
    ryindex:0, //人员规模索引
    renyuanArr:[],//人员规模
    renyuan:'',///上传的人员规模
    shengindex:0,//省索引
    shengArr:[],//省
    shengvalue:'',//上传的省
    province:'',//省编码
    shiindex:0,//市索引
    shiArr:[],//市
    shivalue:'',//上传的市
    city:'',//市编码
    quindex:0,//区索引
    quArr:[],//区
    quvalue:'',//上传的区
    district:'',//区编码
    hangye:'选择行业',
    logo:'',//企业logo
    businessLicenseUrl:'',//上传营业执照
    contentSet:[],//企业相册
    jbrsfzm:'',//经办人身份证明
    yrdwwtzm:'',//用人单位委托证明
    sfzZm:'',//身份证正面
    sfzFm:'',//身份证反面
    startTime:'',//开始时间
    endTime:'',///结束时间
    gswelfare:[],
    welfareval:'',//新增福利
    fuliactive:false,//福利是否选中
    fulistr:'',//
    fuliarr:[],//
    timeStart:60, //倒计时初始值
    timeCur:null, //当前倒计时显示值
    ifTimeIn:false, //是否倒计时中
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    let userInfo = wx.getStorageSync('userInfo')
    // 省
    wx.request({
      url: url + 'area/province',
      method: "GET",
      data:{},
      success:function(res){
        console.log("省",res);
        var ret = res.data
          that.setData({
            shengArr:ret.data,//省
          })
      }
    })
    // 企业性质
    wx.request({
      url: url + 'dict/getEnterpriseNature',
      method: "GET",
      data:{},
      success:function(res){
        console.log("企业性质",res);
        var ret = res.data
          that.setData({
            qiyeArr:ret.data,//企业性质
          })
      }
    })
    // 人员规模
    wx.request({
      url: url + 'dict/getEnterpriseSize',
      method: "GET",
      data:{},
      success:function(res){
        console.log("人员规模",res);
        var ret = res.data
          that.setData({
            renyuanArr:ret.data,//人员规模
          })
      }
    })
    if(!userInfo || !userInfo.id){
      // 新用户，直接注册，不反显数据
      that.setData({ editstate: true })
      // 公司福利
      wx.request({
        url: url + 'dict/getTreatmentState',
        method: "GET",
        data:{},
        success:function(res){
          console.log("公司福利",res);
          var ret = res.data.data
          for(var i in ret){
            var newData = {
              id:i,
              name:ret[i].subTypeName,
              isSelected: true
            }
            that.data.gswelfare.push(newData);
          }
          console.log('福利',that.data.gswelfare)
          that.setData({
            gswelfare:that.data.gswelfare,//人员规模
          })
          
        }
      })
      return
    }
    var date = that.formatTime(new Date);
    that.setData({
      id: userInfo.id
    })
    wx.request({
      url: url + 'enterprise/getEnterpriseInfo?enterprise_id='+ userInfo.id,
      method: "GET",
      success:function(res){
        console.log('企业信息',res)
        if(res.data.code == 200){
          that.data.enterprisedata = res.data.data;
          var newfuli = that.data.enterprisedata.treatment.split(",")
          for(var i in newfuli){
            var newData = {
              id:i,
              name:newfuli[i],
              isSelected: true
            }
            that.data.gswelfare.push(newData);
          }
          that.setData({
            enterprisedata:that.data.enterprisedata,
            dateValue_d_v:date,
            startTime:that.data.enterprisedata.startWorkTime,
            endTime:that.data.enterprisedata.endWorkTime,
            businessLicenseUrl:that.data.enterprisedata.businessLicenseUrl,
            jbrsfzm:that.data.enterprisedata.jbrsfzm,
            logo:that.data.enterprisedata.logo,
            yrdwwtzm:that.data.enterprisedata.yrdwwtzm,
            sfzZm:that.data.enterprisedata.sfzZm,
            sfzFm:that.data.enterprisedata.sfzFm,
            gswelfare:that.data.gswelfare,
            city:that.data.enterprisedata.city,
            district:that.data.enterprisedata.district,
            province:that.data.enterprisedata.province,
            shengvalue:that.data.enterprisedata.province,
            shivalue:that.data.enterprisedata.city,
            quvalue:that.data.enterprisedata.district,
            account:that.data.enterprisedata.account,
            password:that.data.enterprisedata.password,
            password2:that.data.enterprisedata.password,
            smsCode:that.data.enterprisedata.smsCode || '123456',
            name:that.data.enterprisedata.name,
            nickname:that.data.enterprisedata.nickname,
            sociologyCreditCode:that.data.enterprisedata.sociologyCreditCode,
            addressDetail:that.data.enterprisedata.addressDetail,
            renyuan:that.data.enterprisedata.companySize,
            qiye:that.data.enterprisedata.enterpriseNature,
            hangye:that.data.enterprisedata.industry,
            contentSet:that.data.enterprisedata.contentSet,
            contacts:that.data.enterprisedata.contacts,
            mobileNum:that.data.enterprisedata.mobileNum,
            identifyCode:that.data.enterprisedata.identifyCode,
            email:that.data.enterprisedata.email,
            introduction:that.data.enterprisedata.introduction,
          })
        }
      }
    })
  },
  // 用户名
  account(e){
    var that = this
    that.setData({account:e.detail.value})
  },
  // 密码
  password(e){
    var that = this
    that.setData({password:e.detail.value})
  },
  // 重复密码
  password2(e){
    var that = this
    that.setData({password2:e.detail.value})
  },
  // 公司全称
  name(e){
    var that = this
    that.setData({name:e.detail.value})
  },
  // 公司简称
  nickname(e){
    var that = this
    that.setData({nickname:e.detail.value})
  },
  // 统一社会信用代码
  sociologyCreditCode(e){
    var that = this
    that.setData({sociologyCreditCode:e.detail.value})
  },
  //详细地址
  addressDetail(e){
    var that = this
    that.setData({addressDetail:e.detail.value})
  },
  //企业简介
  introduction(e){
    var that = this
    that.setData({introduction:e.detail.value})
  },
  //招聘人姓名
  contacts(e){
    var that = this
    that.setData({contacts:e.detail.value})
  },
  //联系人身份证号
  identifyCode(e){
    var that = this
    that.setData({identifyCode:e.detail.value})
  },
  //联系人手机号
  mobileNum(e){
    var that = this
    that.setData({mobileNum:e.detail.value})
  },
  //短信验证码
  smsCode(e){
    var that = this
    that.setData({smsCode:e.detail.value})
  },
  // 获取验证码
	getMobileVerify(){
		var that = this
		if(!that.data.mobileNum){
			wx.showModal({
				title: '友情提示',
				content: '请输入手机号',
				showCancel: false,
			});
			return false
    }
		if(!/^1\d{10}$/.test(that.data.mobileNum)){
			wx.showModal({
				title: '友情提示',
				content: '请输入正确的手机号',
				showCancel: false,
			});
			return false;
		}
		wx.showLoading({
		  title: "发送中",
		  mask: true
		});
		wx.request({
      url:url+'sms/sandMassage',
      method: "POST",
      data:{
				phoneNumber:that.data.mobileNum
			},
      success:function(res){
        var ret = res.data
        if(ret.code == 200){
					// 执行倒计时
					that.setData({
						timeCur : that.data.timeStart,
						timer : setInterval(that.setTime,1000),
						ifTimeIn : true,
					});
					wx.hideLoading();
					wx.showToast({
            title: '发送成功',
            icon:'none'
					})
        }else{
          wx.showToast({
            title: '发送失败',
            icon:'none'
					})
					wx.hideLoading();
        }
      }
    })
  },
  // 倒计时
	setTime(){
		let timeCur = this.data.timeCur - 1;
		if(timeCur < 0){
			clearInterval(this.data.timer);
			this.setData({
				ifTimeIn:false
			});
			return false;
		}
		this.setData({
			timeCur : timeCur
		});
  },
  //电子邮箱
  email(e){
    var that = this
    that.setData({email:e.detail.value})
  },
  onShow(){
    var that = this
    var hangye = wx.getStorageSync('hangye')
    if(hangye){
      that.setData({hangye:hangye})
    }
  },
  // 所属行业
  hangye(e){
    var that = this
    // that.setData({hangye:e.detail.value})
    wx.navigateTo({
      url: '/HomePage/industry/industry',
    })
  },
  //选择省
  shengChange: function (e){
    var that = this;
    var val = e.detail.value//这个是  index
    var code = ''//这个是  code
    var skill = that.data.shengArr
    for(let item in skill){
      if(item == val){
        that.setData({shengvalue:skill[item].name,province:skill[item].code +'|' + skill[item].name})
        code = skill[item].code
        break;
      }
    }
    console.log(val,code)
    that.setData({shengindex:val})//页面赋值 title:name
    // 市
    wx.request({
      url: url + 'area/city?province_code=' + code,
      method: "GET",
      data:{},
      success:function(res){
        console.log("市",res);
        var ret = res.data
          that.setData({
            shiArr:ret.data,//市
          })
      }
    })
  },
  //选择市
  shiChange: function (e){
    var that = this;
    var val = e.detail.value//这个是  index
    var code = ''//这个是  code
    var skill = that.data.shiArr
    for(let item in skill){
      if(item == val){
        that.setData({shivalue:skill[item].name,city:skill[item].code +'|' + skill[item].name})
        code = skill[item].code
        break;
      }
    }
    console.log(val,code)
    that.setData({shiindex:val,})//页面赋值 title:name
    // 区
    wx.request({
      url: url + 'area/district?city_code=' + code,
      method: "GET",
      data:{},
      success:function(res){
        console.log("区",res);
        var ret = res.data
          that.setData({
            quArr:ret.data,//区
          })
      }
    })
  },
  //选择区
  quChange: function (e){
    var that = this;
    var val = e.detail.value//这个是  index
    var skill = that.data.quArr
    for(let item in skill){
      if(item == val){
        that.setData({quvalue:skill[item].name,district:skill[item].code +'|' + skill[item].name})
        // that.setData({level:skill[item].id,})
        break;
      }
    }
    that.setData({quindex:val,province:that.data.province +','+ that.data.city + ',' + that.data.district})//页面赋值 title:name
    console.log(that.data.province,that.data.city,that.data.district)
  },
  //企业性质
  qiyeChange: function (e){
    var that = this;
    var val = e.detail.value//这个是  index
    var skill = that.data.qiyeArr
    for(let item in skill){
      if(item == val){
        that.setData({qiye:skill[item].subTypeName,})
        // that.setData({level:skill[item].id,})
        break;
      }
    }
    console.log(val)
    that.setData({qyindex:val,})//页面赋值 title:name
  },
  //人员规模
  renyuanChange: function (e){
    var that = this;
    var val = e.detail.value//这个是  index
    var skill = that.data.renyuanArr
    for(let item in skill){
      if(item == val){
        that.setData({renyuan:skill[item].subTypeName,})
        break;
      }
    }
    that.setData({ryindex:val,})//页面赋值 title:name
  },
  chooseImage(e){
    if(!this.data.editstate) return
    let { prop } = e.currentTarget.dataset
    let _this = this
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        if(res.tempFilePaths.length > 0){
          _this.setData({ [prop]: res.tempFilePaths[0]})
          _this.uploadImage(res.tempFilePaths[0], prop)
        }
    }
  })
  },
  uploadImage(filePath, prop){
    let _this = this
    wx.uploadFile({
      url:url + 'enterprise/uploadLicence',
      filePath: filePath,
      header:{ 'Content-Type': 'multipart/form-data'},
      formData:{},
      name: 'enterprise_licence',
      success (res) {
        var resData = JSON.parse(res.data)
        console.log('success:', res, prop)
        if(resData.code == 200) {
          _this.setData({ [prop]: resData.data })
          wx.showToast({
            title: resData.msg,
            icon:'none',
          })
          return
        }
        wx.showToast({
          title: resData.msg || '文件上传失败',
          icon: 'none'
        })
      },
      fail(err){
        console.log('uploadImage err', err, prop)
        wx.showToast({
          title: err.message || '文件上传失败',
          icon: 'none'
        })
      }
    });
  },
  //上传企业相册
  qiyealbumTap(){
    var that = this;
    wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['original', 'compressed'],
        sourceType: ['album', 'camera'],
        success: function (res) {
          console.log(res,res.tempFilePaths)
        if(res.tempFilePaths.length > 0){
            that.qiyeuploadFile(res.tempFilePaths[0])
        }
      }
    })
  },
  qiyeuploadFile: function(tempUrl){
    var that = this
    console.log(tempUrl)
    let userInfo = wx.getStorageSync('userInfo')
    wx.uploadFile({
      url:url+'enterprise/uploadImage',
      filePath: tempUrl,
      header:{ 'Content-Type': 'multipart/form-data'},
      formData:{},
      name: 'enterprise_image',
      success: function (res) {
        var ret=JSON.parse(res.data)
        console.log(ret)
        if (ret.code == 200) {
          wx.request({
            url: url + 'enterprise/addImageToAlbum',
            method: "POST",
            data:{
              enterpriseUid:userInfo.enterpriseUid,
              imageUrl:ret.data
            },
            success:function(res){
              console.log("添加成功",res);
              var resdata = res.data
              if(resdata.code == 200){
                that.data.contentSet.push({
                  id: resdata.data.id,
                  imageUrl: resdata.data.imageUrl
                })
                that.setData({contentSet:that.data.contentSet})
              }
            }
          })
          wx.showToast({
            title: ret.msg,
            icon:'none',
          })
        }
      }
    });
  },
  //删除企业相册
  qiyeDeleteImg: function (e) {
    var that = this
    wx.request({
      url: url + 'enterprise/deleteEnterpriseImage?enterprise_image_id=' + e.currentTarget.dataset.id,
      method: "DELETE",
      data:{},
      success:function(res){
        console.log("删除成功",res);
        if(res.data.code == 200){
          wx.showToast({
            title: res.data.msg,
            icon:'none',
          })
          that.data.contentSet.splice(e.currentTarget.dataset.index, 1)
          that.setData({contentSet:that.data.contentSet})
        }
      }
    })
  },
  welfareSelected: function (e) {
    let index = e.currentTarget.dataset.index;
    if(e.currentTarget.dataset.active == false){
      this.data.fuliactive = true;
    }else{
      this.data.fuliactive = false;
    }
    let item = this.data.gswelfare[index];
    item.isSelected = !item.isSelected;
    this.setData({
      gswelfare: this.data.gswelfare,
    });
    var jiekou = [];
    for (var i in this.data.gswelfare){
      if(this.data.gswelfare[i].isSelected){
        jiekou.push(this.data.gswelfare[i].name);
        this.data.fuliarr = jiekou
        this.data.fulistr = jiekou.join(',')
        console.log('是否选中福利',jiekou,this.data.fuliarr,this.data.fulistr)
      } 
    }
    
  },
  welfarefocus(e){
    var that = this
    that.setData({welfareval:e.detail.value})
  },
  joinWelfare: function (e) {
    var that = this
    if(that.data.welfareval == ''){
      wx.showToast({
        title: '请输入新福利',
        icon:'none',
      })
      return false
    }
    let value = that.data.welfareval
    var gswelfare = that.data.gswelfare;
    var newData = {
      id:that.data.gswelfare.length,
      name:value,
      isSelected: false
    }
    gswelfare.push(newData);
    that.setData({gswelfare:gswelfare})
    that.setData({welfareval:''})
    console.log('备选',value,that.data.welfareval)
  },
 
  bindDateChange: function(e) {
    this.setData({
      startTime: e.detail.value
    })
  },
  jieshuChange: function(e) {
    this.setData({
      // date: e.detail.value,
      endTime: e.detail.value
    })
  },
  formatTime:function(date){
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    if(month < 10){
      month = '0'+month;
    }
    if(day < 10){
      day = '0'+day;
    }
    return year+'-'+month+'-'+day;
  },
  checkSensWords(e){
    let itemData = e.target.dataset;
    let label = Object.values(itemData)[0]
    let key = Object.keys(itemData)[0]
    this.sensWords = this.sensWords || {}
    app.validSensWords(e.detail.value, label).then(() => {
      delete this.sensWords[key]
    }).catch(() => {
      this.sensWords = {...itemData, ...this.sensWords}
    })
  },
  savedata(e){
    var that = this
    var qiyeId = that.data.id
    if(qiyeId > 0){
      //编辑
      var method = 'PUT'
      var api = 'enterprise/updateEnterpriseInfo'
    }else{
      // 注册
      var method = 'POST'
      var api = 'enterprise/register'
    }

    var jiekou = [];
    for (var i in that.data.gswelfare){
      if(that.data.gswelfare[i].isSelected){
        jiekou.push(that.data.gswelfare[i].name);
        that.data.fuliarr = jiekou
        that.data.fulistr = jiekou.join(',')
        that.data.fuliactive = true;
        console.log('最后提交福利数据',jiekou,that.data.fuliarr,that.data.fulistr)
      } 
    }
    var myreg = '^[0-9a-zA-Z]{6,12}$'
    var re = new RegExp(myreg)
    if(that.data.account == '' || that.data.account == undefined){
      wx.showToast({
        title: '请输入用户名',
        icon:'none',
      })
      return false
    }
    if (!re.test(that.data.account)) {
      wx.showModal({
				title: '友情提示',
				content: '用户名请输入6-16位英文或数字',
				showCancel: false,
			});
			return false
    }
    
    if(that.data.password == '' || that.data.password == undefined){
      wx.showToast({
        title: '请输入密码',
        icon:'none',
      })
      return false
    }
    if(that.data.editstate){
      var myregmima = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
      var remima = new RegExp(myregmima)
      if (!remima.test(that.data.password)) {
        wx.showModal({
          title: '友情提示',
          content: '密码请输入6-16位字母与数字组合',
          showCancel: false,
        });
        return false
      }
    }
    if(that.data.password2 == '' || that.data.password2 == undefined){
      wx.showToast({
        title: '请输入重复密码',
        icon:'none',
      })
      return false
    }
    if(that.data.password != that.data.password2){
      wx.showToast({
        title: '密码不一致，请重新输入',
        icon:'none',
      })
      return false
    }
    if(that.data.name == '' || that.data.name == undefined){
      wx.showToast({
        title: '请填写企业全称',
        icon:'none',
      })
      return false
    }
    if(that.data.nickname == '' || that.data.nickname == undefined){
      wx.showToast({
        title: '请填写企业简称',
        icon:'none',
      })
      return false
    }
    var myregqyjc = /^[\u4e00-\u9fa5]+$/
    var reqyjc = new RegExp(myregqyjc)
    if (!reqyjc.test(that.data.nickname)) {
      wx.showToast({
        title: '企业简称请输入汉字并且不超过4个汉字',
        icon:'none',
      })
      return false
    }
    if(that.data.qiye == ''){
      wx.showToast({
        title: '请选择企业性质',
        icon:'none',
      })
      return false
    }
    if(that.data.sociologyCreditCode == '' || that.data.sociologyCreditCode == undefined){
      wx.showToast({
        title: '请填写统一社会信用代码',
        icon:'none',
      })
      return false
    }
    if(that.data.contacts == '' || that.data.contacts == undefined){
      wx.showToast({
        title: '请填写招聘联系人',
        icon:'none',
      })
      return false
    }
    if(that.data.renyuan == ''){
      wx.showToast({
        title: '请选择企业规模',
        icon:'none',
      })
      return false
    }
    if(that.data.mobileNum  == '' || that.data.mobileNum == undefined){
      wx.showToast({
        title: '请填写联系人手机号',
        icon:'none',
      })
      return false
    }
    if(that.data.smsCode  == '' || that.data.smsCode == undefined){
      wx.showToast({
        title: '请填写短信验证码',
        icon:'none',
      })
      return false
    }
    if(that.data.identifyCode == '' || that.data.identifyCode == undefined){
      wx.showToast({
        title: '请填写联系人身份证号',
        icon:'none',
      })
      return false
    }
    if(!that.data.startTime || !that.data.endTime){
      wx.showToast({
        title: '请选择上下班时间',
        icon:'none',
      })
      return false
    }
    if(that.data.email == '' || that.data.email == undefined){
      wx.showToast({
        title: '请填写电子邮箱',
        icon:'none',
      })
      return false
    }
    if(!that.data.hangye || that.data.hangye == '选择行业'){
      wx.showToast({
        title: '请选择所属行业',
        icon:'none',
      })
      return false
    }
    if(that.data.shengvalue == '' || that.data.shengvalue == undefined){
      wx.showToast({
        title: '请选择省',
        icon:'none',
      })
      return false
    }
    if(that.data.shivalue == '' || that.data.shivalue == undefined){
      wx.showToast({
        title: '请选择市',
        icon:'none',
      })
      return false
    }
    if(that.data.quvalue == '' || that.data.quvalue == undefined){
      wx.showToast({
        title: '请选择区',
        icon:'none',
      })
      return false
    }
    if(that.data.addressDetail == '' || that.data.addressDetail == undefined){
      wx.showToast({
        title: '请填写企业所在地详细地址',
        icon:'none',
      })
      return false
    }
    if(that.data.introduction == '' || that.data.introduction == undefined){
      wx.showToast({
        title: '请填写企业介绍',
        icon:'none',
      })
      return false
    }
    if(that.data.logo == ''){
      wx.showToast({
        title: '请上传企业logo',
        icon:'none',
      })
      return false
    }
    if(that.data.jbrsfzm == ''){
      wx.showToast({
        title: '请上传经办人身份证明',
        icon:'none',
      })
      return false
    }
    if(that.data.yrdwwtzm == ''){
      wx.showToast({
        title: '请上传用人单位委托证明',
        icon:'none',
      })
      return false
    }
    if(that.data.businessLicenseUrl == ''){
      wx.showToast({
        title: '请上传营业执照',
        icon:'none',
      })
      return false
    }
    if(that.data.sfzZm == ''){
      wx.showToast({
        title: '请上传企业法人身份证正面',
        icon:'none',
      })
      return false
    }
    if(that.data.sfzFm == ''){
      wx.showToast({
        title: '请上传企业法人身份证反面',
        icon:'none',
      })
      return false
    }
    if(!that.data.editstate){
      if(that.data.contentSet.length == 0){
        wx.showToast({
          title: '请上传企业相册',
          icon:'none',
        })
        return false
      }
    }
    console.log('福利是否选中',this.data.fuliactive)
    if(that.data.fuliactive == false){
      wx.showToast({
        title: '请选择公司福利（多选）',
        icon:'none',
      })
      return false
    }
    if(that.sensWords != undefined){
      let sensWords = Object.values(that.sensWords)
      if(sensWords.length > 0){
        wx.showToast({
          title: `${sensWords.join(',')}包含敏感词，请修改后再${that.data.sttsname}`,
          icon:'none',
        })
        return false;
      }
    }
    
    var data = {
      approval: 1, // 1审核中 2审核通过  3审核不通过
      account:that.data.account,
      password: util.strEncode(that.data.password),
      approvalResultInfo:that.data.enterprisedata.approvalResultInfo,
      enterpriseInfo:that.data.enterprisedata.enterpriseInfo,
      enterpriseNature:that.data.qiye,
      enterpriseUid:that.data.enterprisedata.enterpriseUid,
      headerUrl:that.data.enterprisedata.headerUrl,
      isCollection:that.data.enterprisedata.isCollection,
      isGood:that.data.enterprisedata.isGood,
      jbrsfzm:that.data.jbrsfzm,
      jzyy: that.data.enterprisedata.jzyy,
      locked: that.data.enterprisedata.locked,
      logo: that.data.logo,
      positionNum:that.data.enterprisedata.positionNum,
      realName: that.data.enterprisedata.realName,
      salt: that.data.enterprisedata.salt,
      sfzFm: that.data.sfzFm,
      sfzZm: that.data.sfzZm,
      smsCode: that.data.smsCode,
      updateTime: that.data.enterprisedata.updateTime,
      userType:that.data.enterprisedata.userType,
      yrdwwtzm: that.data.yrdwwtzm,
      userUid: that.data.enterprisedata.userUid,
      zprs: that.data.enterprisedata.zprs,
      name:that.data.name,//公司名称
      nickname:that.data.nickname,//公司名称
      sociologyCreditCode:that.data.sociologyCreditCode,//统一社会信用代码
      industry:that.data.hangye,//所属行业
      companySize:that.data.renyuan,//人员规模
      businessLicenseUrl:that.data.businessLicenseUrl,//营业执照
      city:that.data.city,
      district:that.data.district,
      province:that.data.province,//地点
      addressDetail:that.data.addressDetail,//详细地址
      introduction:that.data.introduction,//企业简介
      startWorkTime:that.data.startTime,//上班时间
      endWorkTime:that.data.endTime,//下班时间
      contacts:that.data.contacts,//招聘人姓名
      identifyCode:that.data.identifyCode,//联系人身份证号
      mobileNum:that.data.mobileNum,//联系人手机号
      email:that.data.email,//电子邮箱
      id:qiyeId,//企业ID
      treatment:that.data.fuliarr.join(','),//公司福利
      // fuliarr:that.data.fuliarr
    }
    console.log('提交数据',data,qiyeId,that.data.fulistr,that.data.fuliarr,that.data.gswelfare);
    wx.request({
      url:url + api,
      header:{ 'context-type': 'application/json',},
      method: method,
      data: data,
      success(res){
        var ret = res.data
        wx.removeStorageSync('hangye')
        if(ret.code == 200){
            wx.showToast({
              title: qiyeId ? '保存成功' : '注册成功, 请重新登录',
              icon:'none',
            })
            if(qiyeId > 0){
              setTimeout(function(){
                wx.navigateBack({
                  delta: 1,
                })
              },1000)
            }else{
              wx.setStorageSync('userType', EnumUserType.QiYe)
              setTimeout(function(){
                wx.reLaunch({
                  url: '/Company/login/login',
                })
              },1500)
            }
        } else {
          wx.showToast({
            title: `${qiyeId ? '保存失败' : '注册失败'}, ${ret.msg}`,
            icon: 'none',
          })
        }
      },
      fail(err){
        wx.showToast({
          title: `${qiyeId ? '保存失败' : '注册失败'}: ${err.msg}`,
          icon: 'none',
        })
      }
    })
  }
})